''' 中间件 '''
from django.http import HttpResponse


class MagMiddleware1:
    def __init__(self, get_response):
        """执行一次"""
        print(self.__class__.__name__, "自定义中间件1——init~~~~")
        self.get_response = get_response

    def __call__(self, request):
        # request请求去视图的路上
        print(self.__class__.__name__, "自定义中间件1-request请求去视图的路上__call__~~~~")
        # return HttpResponse(self.__class__.__name__) # 测试点
        response = self.get_response(request)
        # 内层函数调用完成返回response的路上
        print(self.__class__.__name__, "自定义中间件1-返回response的路上__call__#####")
        return response

class MagMiddleware2:
    def __init__(self, get_response):
        """执行一次"""
        print(self.__class__.__name__, "自定义中间件2——init~~~~")
        self.get_response = get_response

    def __call__(self, request):
        # request请求去视图的路上
        print(self.__class__.__name__, "自定义中间件2-request请求去视图的路上__call__~~~~")
        # return HttpResponse(self.__class__.__name__) # 测试点
        response = self.get_response(request)
        # 内层函数调用完成返回response的路上
        print(self.__class__.__name__, "自定义中间件2-返回response的路上__call__#####")
        return response
